﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Obj;

public partial class AreaRestrita_MarcaForm : PageBase
{
    int MarcaID;
    protected void Page_Load(object sender, EventArgs e)
    {
        ValidarUsuario();
        if (!IsPostBack)
        {
            if (Session["MarcaID"] != null)
            {
                MarcaID = Convert.ToInt32(Session["MarcaID"]);
                Session["MarcaID"] = null;
                hdfID.Value = MarcaID.ToString();

                objMarca Marca = new objMarca(MarcaID);
                BLLMarca regra = new BLLMarca();

                Marca = regra.marca(Marca);
                CarregarTela(Marca);
            }
        }
    }

    protected void CarregarTela(objMarca Marca)
    {
        txtMarca.Text = Marca.Descricao;
    }
    protected void btnSalvar_Click(object sender, EventArgs e)
    {
        BLLMarca regra = new BLLMarca();
        objMarca marca = new objMarca(txtMarca.Text);
        if ((hdfID.Value != null) && (hdfID.Value != ""))
        {
            marca.MarcaID = Convert.ToInt32(hdfID.Value);
            regra.Save(marca, action.UPDATE);
            ScriptManager.RegisterClientScriptBlock(
            this,
            typeof(Page),
            "ToggleScript",
            "alert('Marca alterada com sucesso!');window.location.href='Marca.aspx'",
            true);
        }
        else
        {
            regra.Save(marca, action.INSERT);
            ScriptManager.RegisterClientScriptBlock(
            this,
            typeof(Page),
            "ToggleScript",
            "alert('Marca incluída com sucesso!');window.location.href='Marca.aspx'",
            true);            
        }
    }
}